package top.suven.base.core.mq.rocketmq;

import org.apache.rocketmq.client.producer.DefaultMQProducer;
import org.apache.rocketmq.common.message.Message;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * @ClassName:
 * @Description:
 * @Author lixiangling
 * @Date 2018/6/27 15:53
 * @Copyright: (c) 2018 gc by https://www.gc.com.cn/
 * @Version : 1.0.0
 * --------------------------------------------------------
 * modifyer    modifyTime                 comment
 * <p>
 * --------------------------------------------------------
 */
public class RocketMQThread implements Runnable {
    private Logger logger = LoggerFactory.getLogger(RocketMQThread.class);
    private Message message;
    private DefaultMQProducer defaultMQProducer;

    public RocketMQThread(Message message, DefaultMQProducer defaultMQProducer){
        this.message = message;
        this.defaultMQProducer = defaultMQProducer;
    }
    @Override
    public void run() {
        try {
             defaultMQProducer.send(message);
        }catch (Exception e) {
            logger.error(String.format("producer send message is error topic=%s,tags=%s,msg=%s", message.getTopic(),message.getTags(),new String(message.getBody())),e);
        }
    }
}
